// SPDX-FileCopyrightText: 2023-2025 Sangfor Technologies Inc.
// SPDX-License-Identifier: Mulan PSL v2
package entity

type NotebookStatus string

const (
	NotebookRunning  NotebookStatus = "running"
	NotebookStarting NotebookStatus = "starting"
	NotebookStopped  NotebookStatus = "stopped"
	NotebookFailed   NotebookStatus = "failed"

	NotebookHomePath    = "/home/jovyan"
	ModelsPath          = "/mnt/models"
	VolumeModelsSubPath = ".aip_system/models"
)

// notebook结构体
type Notebook struct {
	ID     string `json:"id,omitempty" gorm:"primarykey"`                                     // user id + name
	Name   string `json:"name" gorm:"type:varchar(30)" binding:"min=1,max=30" example:"nb-1"` // name of notebook in k8s, and will be displayed on UI
	UserID string `json:"userID" gorm:"type:varchar(255)"`                                    // user ID
	ModifyNotebook

	//VolumeMounts []VolumeMount  `json:"volumeMounts"`
	NewVolume     bool   `json:"newVolume" gorm:"-"`
	VolumeName    string `json:"volumeName" gorm:"type:varchar(255)" binding:"min=1,max=30" example:"nb-data"`
	WorkspaceSize int64  `json:"workspace" gorm:"type:int(32)" binding:"required,min=1,max=1024000" example:"10"`

	UpdateTime    int    `json:"updateTime" gorm:"type:int(32);autoUpdateTime"` //column name; auto create and update time
	CreateTime    int    `json:"createTime" gorm:"type:int(32);autoCreateTime"` //开始时间：2020-12-21 10:00 column name; auto create and update time
	LastActive    int    `json:"lastActive" gorm:"type:int(32)"`
	Url           string `json:"url" gorm:"-"`
	VscodeUrl     string `json:"vscodeUrl" gorm:"-"` // vscode url
	ClearLeftTime int    `json:"clearLeftTime" gorm:"-"`
	//ProjectID     string         `json:"projectId" gorm:"type:varchar(255)" binding:"required"` // project ID
	// 去掉项目，设置参数为非必填，后台默认设置一个项目id
	ProjectID string         `json:"projectId" gorm:"type:varchar(255)" ` // project ID
	Status    NotebookStatus `json:"status" gorm:"type:varchar(30)" `
}

// 能修改的notebook结构体
type ModifyNotebook struct {
	Description     string `json:"description" gorm:"type:varchar(300)" binding:"max=300"`
	Image           string `json:"image" gorm:"type:varchar(300)" binding:"required" example:"registry.geniusai.com/modelserver/ueba:0.1"`
	CpuNum          int64  `json:"cpuNum" gorm:"type:int(32)" binding:"required,min=1,max=256"  example:"1"` //min=1,max=256
	GpuNum          int64  `json:"gpuNum" gorm:"type:int(32)"  example:"1"`                                  //min=1,max=256
	GpuName         string `json:"gpuName" gorm:"column:gpu_name;type:varchar(20)"`
	VGpuNum         int64  `json:"vGpuNum" gorm:"column:vgpu_num;type:int(32)"` //min=0,max=256
	VGpuDisplayName string `json:"vGpuDisplayName" gorm:"column:vgpu_display_name;type:varchar(20)"`
	IsVGpu          bool   `json:"isVGpu" gorm:"column:is_vgpu;type:tinyint(1)"`
	VGpuMemory      int64  `json:"vGpuMemory" gorm:"column:vgpu_memory;type:int(32)"`                           //min=0,max=256
	MemorySize      int64  `json:"memorySize" gorm:"type:int(32)" binding:"required,min=1,max=256" example:"2"` //min=1,max=256
}

// 获取namespace
func (n *Notebook) GetNamespace() string {
	return n.UserID
}
